package com.aaa.controller;

import com.aaa.entity.Role;
import com.aaa.service.RoleServiceDao;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("role")
public class RoleController {
    @Resource
    RoleServiceDao roleserviceDao;

    @RequestMapping("find")
    @ResponseBody
    public List<Role> find(){
        return roleserviceDao.find();
    }


    @RequestMapping("add")
    @ResponseBody
    public int add(Role role){
        return roleserviceDao.add(role);
    }


    @RequestMapping("update")
    @ResponseBody
    public int update(Role role){
        return roleserviceDao.update(role);
    }


    @RequestMapping("delete")
    @ResponseBody
    public int delete(Integer rid){
        return roleserviceDao.delete(rid);
    }

    @ResponseBody
    @RequestMapping("findpage")
    public Map<String, Object> findpage(Integer pageSize, Integer pageNum) {
        Map<String, Object> map = new HashMap<>();
        List<Role> userList = roleserviceDao.findpage(pageSize, pageNum * pageSize);
        Integer TotalNum = roleserviceDao.findcount();

        map.put("userList", userList);
        map.put("TotalNum", TotalNum);
        return map;
    }
}
